package Algorithm;

public class BinarySearch {
    public static int binarySearch(int[] array,int k,int left,int right){
        if(left>right)return -1;
        int mid=left+((right-left)>>1);
        if(array[mid]==k){
            return mid;
        }else if(array[mid]>k){
            return binarySearch(array,k,left,mid-1);
        }else{
            return binarySearch(array,k,mid+1,right);
        }
    }
    public static void main(String[] args) {
        int[] array=new int[]{1,2,3,4,5,6,7,8,9,12,15,16,17,18};
        System.out.println(binarySearch(array,12,0,array.length-1));
    }
}
